//获取应用实例
var app = getApp()
var network = require("../../../utils/network.js")
Page({  
    data: {
      problem:[
        { title: "古董字画、博古架、贵重灯具、装饰品，绿植，家居内部和顶棚不在清洁范围之内", content:"", id:0},
        { title: "开荒、擦玻璃、除油不在日常保洁服务范围内，小主请根据需求预约哦", content:"", id:1 },
        { title: "保洁服务在指定节假日期间（例如：春节等）价格会有所波动，最终结算价格以预约服务时活速帮的正常销售价为准", content: "", id: 2 },
        { title: "若实际服务时长超过预约时长，服务结束后需按保洁师提供的最终结算价结算，超出部分款项支持现金支付", content: "", id: 3 }
      ]                     
    },
    hoursChange: function (e) {    
      var that = this  
      this.setData({
        ischecked: e.detail.value,   
      })
      var moneyID = e.detail.value
      var arrayK = this.data.selectable
      var duration = arrayK[moneyID].hour
      wx.setStorageSync("duration", duration)
      var openid = wx.getStorageSync("openid")
      var data = {}
      data.openid = openid
      data.duration = duration*60
      data.usersId = ""
      wx.request({
        url: "https://api.hsb1234.com/userc/v1/service/category/baojie",
        data:data,
        header: {
          'content-Type': 'application/json'
        },
        method: "POST",
        success: function (res) {
          if (res.statusCode == 200) {
            var resdata = res.data.data
            console.log(resdata)
            var curPrice = resdata.curPrice
            console.log(that.data.selectable)
            that.setData({
              curPrice: curPrice,
            })
          } else {

          }
        },
        fail: function (res) {
          if (res.statusCode == 401) {
            wx.navigateTo({
              url: '../../public/login/index',
            })
          } else {
            wx.showModal({
              title: '提示',
              content: '加载失败请检查您的网络',
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
        },
      })
      that.setData({
        hour: arrayK[moneyID].hour,
        id: arrayK[moneyID].id
      })
    },  
    toHcAppointment:function(){
      wx.navigateTo({
        url: '../hc-appointment/index',
      })    
    },
    onLoad: function() {       
        var that = this
        var openid = wx.getStorageSync("openid")
        var data = {}
        data.openid = openid
        network.getData(
          "https://api.hsb1234.com/userc/v1/service/category/baojie",
          data,
          function(res){
            console.log(res)
            var resData = res.data.data
            var selectable1 = resData.selectable
            var selectable=[]
            for (var i = 0; i < selectable1.length; i++){
              selectable[i]={}
              selectable[i].hour = selectable1[i]
              selectable[i].id = i
            }
            console.log(selectable)
           that.setData({
             banner: resData.banners[1].url,
             name: resData.name,
             desc: resData.desc,
             selectable: selectable
           })
          },
          function(res){
          }
        )
        var duration = 3
        wx.setStorageSync("duration", duration)
        var openid = wx.getStorageSync("openid")
        var data = {}
        data.openid = openid
        data.duration = duration*60
        data.usersId = ""
        network.postData(
          "https://api.hsb1234.com/userc/v1/calculation/price",
          data,
          function (res) {
            var resdata = res.data.data
            console.log(resdata)
            var curPrice = resdata.curPrice
            console.log(that.data.selectable)
            that.setData({
              curPrice: curPrice,
              hour: 3,
              id: 1,
              ischecked: 1
            })
          },
          function () {
          }
        )
        // 设置默认的时间费用信息
        
        //更新数据获取用户信息
        app.getUserInfo(function(userInfo) {  
            that.setData({
                userInfo: userInfo
            })           
        })
    },
    // 分享
    onready:function(){
      var that = this 
      
    },
    onShareAppMessage: function () {
      return {
        title: "活速帮提供优质家政服务，让您畅享舒适生活",
        desc: "",
        path: "/main/index",
        success: function () {
          wx.showToast({
            title: '成功',
            icon: 'success', 
            imageUrl: "http://housecleanimags-1255598775.file.myqcloud.com/screen/swiper1.jpg",
            duration: 500
          })
        },
        fail: function () {
          wx.showToast({
            title: "谢谢体验",
            icon: 'fail',
            duration: 500
          })
        }
      }
    },
})
